import BeforeRouter from './permission'
import { ConfigProvider, theme } from 'antd'
import { useState } from 'react'
import { usePreferredColorScheme } from '@reactuses/core'
import { useSelector, useDispatch } from 'react-redux'
import { Rootstate } from '@/store'

function App() {
  // 获取系统主题
  const color = usePreferredColorScheme()

  const dispatch = useDispatch()
  const { theme: _theme } = useSelector((state: Rootstate) => ({
    theme: state.settings.theme
  }))

  if (!_theme) {
    dispatch({
      type: 'updateTheme',
      payload: {
        theme: color
      }
    })
  }

  // 设置主题
  const [themeColor, setThemeColor] = useState('defaultAlgorithm')
  // _theme === 'dark' && setThemeColor('darkAlgorithm')

  return (
    <ConfigProvider
      // theme={{
      //   algorithm: theme[themeColor]
      // }}
    >
      <div className="app">{BeforeRouter()}</div>
    </ConfigProvider>
  )
}

export default App
